Written by Jerry ┼man, Optima System, May 19, 1996.
We will not be held responsible for any unwanted
effects due to the usage of this script or any derivative.
No warrantees for usability for any specific application are given
or implied.
*/
function GetRandomURL()
{
// Put relative or full URL's in the strings below
// You can increase the number of URL's to more than 5 by adding a
// string containing an URL in list below
var locationlist = new URLList (
"harpo.html",
"groucho.html",
"chico.html",
"zeppo.html",
"Java Scrolling Text Stationery"
);
num = Math.round ( ( rand.next() * (locationlist.count-1)) );
return locationlist.list[num];
}
function URLList () {
var argv = URLList.arguments;
var argc = argv.length;
this.list = new Object();
for (var i = 0; i < argc; i++)
this.list[i] = argv[i];
this.count = argc;
return this;
}
//*********************************************
// Park-Miller Pseudo-Random Number Generator
// JavaScript implementation by David N. Smith
// of IBM's T J Watson Research Center
//*********************************************
function NextRandomNumber() {
var hi = this.seed / this.Q;
var lo = this.seed % this.Q;
var test = this.A * lo - this.R * hi;
if (test > 0)
this.seed = test;
else
this.seed = test + this.M;
return (this.seed * this.oneOverM);
}
function RandomNumberGenerator() {
var d = new Date();
this.seed = 2345678901 +
(d.getSeconds() * 0xFFFFFF) +
(d.getMinutes() * 0xFFFF);
this.A = 48271;
this.M = 2147483647;
this.Q = this.M / this.A;
this.R = this.M % this.A;
this.oneOverM = 1.0 / this.M;
this.next = NextRandomNumber;
return this;
}
var rand = new RandomNumberGenerator();
// -- End of JavaScript code -------------- -->
</SCRIPT>
</HEAD>
<BODY>
<H1>JavaScript Random Link</H1>
<B>This stationery page contains:</B>
<BR>
<B><UL>
<LI>a JavaScript that selects a random URL
<LI>a link that displays an alert
</UL>
Please note that JavaScript is currently only available in Netscape Navigator 2.0 or higher.
</B>
<P>
The script is named <B>GetRandomURL</B> and it is placed in the HEAD section of the HTML document. The script is executed by clicking on a link containing a call to GetRandomURL(). Also note the <FONT COLOR="FF3366">custom text</FONT> in Netscapes status area.
<P>
Example of this script picking a
<A HREF=""
onClick="this.href=GetRandomURL()"
onMouseOver="window.status='This link goes to a randomly selected page'; return true">random</A> page.
<P>
<B>How to use:</B><BR>
Replace the filenames inside the script with your own URLs and edit this page contents inside the <BODY> section. (You can also copy the entire script to an existing page).